$(function () {
    var myChart = echarts.init(document.getElementById('main'));

    $.ajax({
        url: '/getGradeCount',
        type: 'get',
        success: function (data) {
            var sum = 0
            for (var i = 0; i <= data.length-1; i++){
                sum += data[i]
                $("#counttable").find("tr").eq(i+1).find("td").eq(1).html(data[i])
            }

            $("#count").html(sum)
            var option = {
                color: ['#3398DB'],
                title: {
                    text: '等级统计柱状图',
                    left: 'center'
                },
                tooltip: {
                    trigger: 'axis',
                    axisPointer: {            // 坐标轴指示器，坐标轴触发有效
                        type: 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
                    }
                },
                grid: {
                    left: '5%',
                    right: '10%',
                    bottom: '5%',
                    containLabel: true
                },
                xAxis: [
                    {
                        name:'等级',
                        nameLocation:'middle',
                        nameTextStyle:{
                            color:"black",
                            fontSize:16,
                            padding:10
                        },

                        type: 'category',
                        data: ['A', 'B', 'C'],
                        axisTick: {
                            alignWithLabel: true
                        }
                    }
                ],
                yAxis: [
                    {
                        type: 'value',
                        name:'人数',
                        nameLocation:'middle',
                        nameTextStyle:{
                            color:"black",
                            fontSize:16,
                            padding:10
                        },
                    }
                ],
                series: [
                    {
                        name: '人数：',
                        type: 'bar',
                        barWidth: '60%',
                        data: data
                    }
                ]
            };
            setTimeout(myChart.setOption(option), 2000)
        }
    })

})
